<template>
  <el-scrollbar wrap-class="scrollbar-wrapper">
    <el-menu
      class="el-left-menu"
      background-color="#304156 "
      text-color="#fff"
      active-text-color="#1890ff"
      :unique-opened="true"
      :collapse="hideLeft"
      :router="true"
      :default-active="currentMenuItem.path"
      :collapse-transition="false"
    >
      <template v-for="m1 in menuList">
        <!-- 是否有二级菜单 无-->
        <el-menu-item
          v-if="m1.children == null"
          :index="m1.path"
          :key="m1.id"
          @click="savePath(m1)"
        >
          <template>
            <!-- 图标 -->
            <i :class="m1.icon"></i>
            <!-- 文本 -->
            <span slot="title">{{ m1.title }}</span>
          </template>
        </el-menu-item>

        <!-- 二级菜单 -->
        <el-submenu v-else :index="m1.id" :key="m1.id">
          <template slot="title">
            <i :class="m1.icon"></i>
            <span>{{ m1.title }}</span>
          </template>
          <template v-for="m2 in m1.children">
            <!-- 是否有三级菜单 无-->
            <el-menu-item
              v-if="m2.children == null"
              :index="m2.path"
              :key="m2.id"
              @click="savePath(m2)"
            >
              <template>
                <i :class="m2.icon"></i>
                <span slot="title">{{ m2.title }}</span>
              </template>
            </el-menu-item>

            <!-- 三级菜单 -->
            <el-submenu v-else :index="m2.id" :key="m2.id">
              <template slot="title">
                <i :class="m2.icon"></i>
                <span>{{ m2.title }}</span>
              </template>
              <el-menu-item
                :index="m3.path"
                v-for="m3 in m2.children"
                :key="m3.id"
                @click="savePath(m3)"
              >
                <template slot="title">
                  <i :class="m3.icon"></i>
                  <span>{{ m3.title }}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </template>
        </el-submenu>
      </template>
    </el-menu>
  </el-scrollbar>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  computed: {
    ...mapGetters({
      hideLeft: 'menu/getHideLeft',
      menuList: 'menu/getMenuList',
      currentMenuItem: 'menu/getCurrentMenuItem'
    })
  },
  methods: {
    savePath(item) {
      this.$store.commit('menu/addTagsViewItem', item)
      this.$store.commit('menu/setBreadcrumbList', item)
      this.$store.commit('menu/setCurrentMenuItem', item)
    }
  }
}
</script>
<style lang="less" scoped>
.el-scrollbar{
  height: 100%;
}
</style>
